package com.liaoye.hellocustomview.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.liaoye.hellocustomview.R;

public class CustomTextView extends AppCompatTextView {
    public CustomTextView(Context context) {
        super(context);
    }

    public CustomTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        //获取attrs中CustomTextView定义的属性的值
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomTextView);
        float headerHeight = typedArray.getDimension(R.styleable.CustomTextView_headerHeight, -1);
        int age = typedArray.getInt(R.styleable.CustomTextView_age, -1);
        typedArray.recycle();
        setText("headerHeight = " + headerHeight + " age = " + age);


    }

    public CustomTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
}
